package com.example.myapplication.ui.news.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.myapplication.R;
import com.example.myapplication.app.App;
import com.example.myapplication.model.bean.VideoData;
import com.xiao.nicevideoplayer.NiceVideoPlayer;
import com.xiao.nicevideoplayer.NiceVideoPlayerController;

import java.util.List;


/**
 * Created by meishiyiyun on 2017/6/14.
 */

public class VideoAdapter extends BaseQuickAdapter<VideoData> {
    public VideoAdapter(int layoutResId, List<VideoData> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, VideoData videoData) {
        Glide.with(mContext).load(videoData.getTopicImg()).into(((ImageView) helper.getView(R.id.iv_logo)));
        helper.setText(R.id.tv_from,videoData.getTopicName());
        helper.setText(R.id.tv_play_time,String.format(App.getInstance().getResources().getString(R.string.video_play_times), String.valueOf(videoData.getPlayCount())));
        NiceVideoPlayer mVideoPlayer = (NiceVideoPlayer) helper.getView(R.id.nice_video_player);
        NiceVideoPlayerController controller = new NiceVideoPlayerController(mContext);
        mVideoPlayer.setController(controller);
        controller.setTitle(TextUtils.isEmpty(videoData.getDescription())?videoData.getTitle()+"":videoData.getDescription());
        controller.setImage( videoData.getCover());
        mVideoPlayer.setUp(videoData.getMp4_url(), null);
        mVideoPlayer.setPlayerType(NiceVideoPlayer.PLAYER_TYPE_IJK);
    }
}
